| Conditions | 1 | 
| Paths | 48 | 
| Total Lines | 894 | 
| Code Lines | 3 | 
| Lines | 894 | 
| Ratio | 100 % | 
| Changes | 3 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | /******/ (function(modules) { // webpackBootstrap | 
            |
| 79 | (function ($) { | 
            ||
| 80 | |||
| 81 | // Add isValid()  | 
            ||
| 82 | |||
| 83 |                     $.fn.isValid = function () { | 
            ||
| 84 | return this[0].checkValidity();  | 
            ||
| 85 | };  | 
            ||
| 86 | |||
| 87 |                     $(document).ready(function () { | 
            ||
| 88 | |||
| 89 | // Accordion Handlers ==================================================  | 
            ||
| 90 | |||
| 91 |                                         function accordionTrigger(trigger) { | 
            ||
| 92 |                                                             if ($(trigger).parent(".accordion").hasClass("active")) { | 
            ||
| 93 |                                                                                 $(trigger).attr("aria-expanded", "false"); | 
            ||
| 94 |                                                                                 $(trigger).parent(".accordion").removeClass("active"); | 
            ||
| 95 |                                                                                 $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); | 
            ||
| 96 |                                                             } else { | 
            ||
| 97 |                                                                                 $(trigger).attr("aria-expanded", "true"); | 
            ||
| 98 |                                                                                 $(trigger).parent(".accordion").addClass("active"); | 
            ||
| 99 |                                                                                 $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); | 
            ||
| 100 | }  | 
            ||
| 101 | }  | 
            ||
| 102 | |||
| 103 |                                         $(document).on("click", ".accordion-trigger", function (e) { | 
            ||
| 104 | |||
| 105 | accordionTrigger(this);  | 
            ||
| 106 | });  | 
            ||
| 107 | |||
| 108 |                                         $(document).on("keyup", ".accordion-trigger", function (e) { | 
            ||
| 109 | |||
| 110 |                                                             if (e.which == 13) { | 
            ||
| 111 | accordionTrigger(this);  | 
            ||
| 112 | }  | 
            ||
| 113 | });  | 
            ||
| 114 | |||
| 115 | // Modal Handlers ======================================================  | 
            ||
| 116 | |||
| 117 |                                         function openModal(trigger) { | 
            ||
| 118 | |||
| 119 |                                                             var modalID = $(trigger).attr("data-modal-id"); | 
            ||
| 120 |                                                             var modal = $(".modal[data-modal-id=" + modalID + "]"); | 
            ||
| 121 |                                                             var modalObject = $(trigger).parents(".modal-target-object"); | 
            ||
| 122 |                                                             $(".modal-overlay").addClass("active"); | 
            ||
| 123 |                                                             modal.addClass("active"); | 
            ||
| 124 |                                                             $("body").css("overflow", "hidden"); | 
            ||
| 125 | |||
| 126 | // Tab Items  | 
            ||
| 127 | |||
| 128 |                                                             var focusableItems = modal.find(":focusable"); | 
            ||
| 129 | |||
| 130 | var firstInput = focusableItems.first();  | 
            ||
| 131 | var lastInput = focusableItems.last();  | 
            ||
| 132 | |||
| 133 |                                                             if (modal.find("form").length == 0) { | 
            ||
| 134 | lastInput.focus();  | 
            ||
| 135 |                                                             } else { | 
            ||
| 136 | firstInput.focus();  | 
            ||
| 137 | }  | 
            ||
| 138 | |||
| 139 | modalTabHandler(firstInput, lastInput);  | 
            ||
| 140 | modalDeleteTrigger(trigger, modal, modalObject);  | 
            ||
| 141 | escapeModalHandler();  | 
            ||
| 142 | }  | 
            ||
| 143 | |||
| 144 |                                         $(document).on("click", ".modal-trigger", function (e) { | 
            ||
| 145 | |||
| 146 | openModal(this);  | 
            ||
| 147 | });  | 
            ||
| 148 | |||
| 149 |                                         $(document).on("keyup", ".modal-trigger", function (e) { | 
            ||
| 150 | |||
| 151 |                                                             if (e.which == 13) { | 
            ||
| 152 | openModal(this);  | 
            ||
| 153 | }  | 
            ||
| 154 | });  | 
            ||
| 155 | |||
| 156 |                                         function closeModal(trigger) { | 
            ||
| 157 | |||
| 158 |                                                             $(".modal-overlay").removeClass("active"); | 
            ||
| 159 |                                                             $(".modal").removeClass("active"); | 
            ||
| 160 |                                                             $("body").css("overflow", "visible"); | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 |                                         $(document).on("click", ".modal-cancel-trigger", function (e) { | 
            ||
| 164 | |||
| 165 | closeModal(this);  | 
            ||
| 166 | });  | 
            ||
| 167 | |||
| 168 |                                         $(document).on("keyup", ".modal-cancel-trigger", function (e) { | 
            ||
| 169 | |||
| 170 |                                                             if (e.which == 13) { | 
            ||
| 171 | closeModal(this);  | 
            ||
| 172 | }  | 
            ||
| 173 | });  | 
            ||
| 174 | |||
| 175 | // Delete Trigger ==================================================  | 
            ||
| 176 | |||
| 177 |                                         function modalDeleteTrigger(trigger, modal, object) { | 
            ||
| 178 | |||
| 179 |                                                             $(document).on("click", ".modal-delete-trigger", function (e) { | 
            ||
| 180 | |||
| 181 | closeModal(trigger);  | 
            ||
| 182 | |||
| 183 | $(object).remove();  | 
            ||
| 184 | });  | 
            ||
| 185 | }  | 
            ||
| 186 | |||
| 187 | // Tab Handler =====================================================  | 
            ||
| 188 | |||
| 189 |                                         function modalTabHandler(first, last) { | 
            ||
| 190 | |||
| 191 |                                                             $(document).on("keydown", function (e) { | 
            ||
| 192 | |||
| 193 | var keyCode = e.keyCode || e.which;  | 
            ||
| 194 | |||
| 195 |                                                                                 if (keyCode == 9 && !e.shiftKey) { | 
            ||
| 196 | |||
| 197 |                                                                                                     if ($(last).is(":focus")) { | 
            ||
| 198 | e.preventDefault();  | 
            ||
| 199 | $(first).focus();  | 
            ||
| 200 | }  | 
            ||
| 201 |                                                                                 } else if (keyCode == 9 && e.shiftKey) { | 
            ||
| 202 | |||
| 203 |                                                                                                     if ($(first).is(":focus")) { | 
            ||
| 204 | e.preventDefault();  | 
            ||
| 205 | $(last).focus();  | 
            ||
| 206 | }  | 
            ||
| 207 | }  | 
            ||
| 208 | });  | 
            ||
| 209 | }  | 
            ||
| 210 | |||
| 211 | // Escape Handler ==================================================  | 
            ||
| 212 | |||
| 213 |                                         function escapeModalHandler() { | 
            ||
| 214 | |||
| 215 |                                                             $(document).on("keyup", function (e) { | 
            ||
| 216 | |||
| 217 |                                                                                 if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) { | 
            ||
| 218 | |||
| 219 |                                                                                                     $(".modal-overlay").removeClass("active"); | 
            ||
| 220 |                                                                                                     $(".modal").removeClass("active"); | 
            ||
| 221 |                                                                                                     $("body").css("overflow", "visible"); | 
            ||
| 222 | |||
| 223 | // FF and compatible  | 
            ||
| 224 |                                                                                                     if (e.stopPropagation) { | 
            ||
| 225 | e.stopPropagation();  | 
            ||
| 226 | e.preventDefault();  | 
            ||
| 227 | }  | 
            ||
| 228 | }  | 
            ||
| 229 | });  | 
            ||
| 230 | }  | 
            ||
| 231 | |||
| 232 | // Form Handlers =======================================================  | 
            ||
| 233 | |||
| 234 | // Required Fields  | 
            ||
| 235 | |||
| 236 |                                         function requiredFields() { | 
            ||
| 237 |                                                             $("input:required, textarea:required").each(function (e) { | 
            ||
| 238 |                                                                                 $(this).parent().addClass("required"); | 
            ||
| 239 |                                                                                 $(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); | 
            ||
| 240 | });  | 
            ||
| 241 | }  | 
            ||
| 242 | |||
| 243 | requiredFields();  | 
            ||
| 244 | |||
| 245 | // Label Handers ===================================================  | 
            ||
| 246 | |||
| 247 |                                         function labelHandlers() { | 
            ||
| 248 | |||
| 249 |                                                             $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function (e) { | 
            ||
| 250 |                                                                                 $(this).parent().addClass("active"); | 
            ||
| 251 | });  | 
            ||
| 252 | |||
| 253 |                                                             $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function (e) { | 
            ||
| 254 | |||
| 255 | // Check for existing value.  | 
            ||
| 256 | |||
| 257 |                                                                                 if ($(this).val() == "") { | 
            ||
| 258 |                                                                                                     $(this).parent().removeClass("active"); | 
            ||
| 259 | }  | 
            ||
| 260 | |||
| 261 | // Check Validity  | 
            ||
| 262 | |||
| 263 |                                                                                 if ($(this).isValid() == true) { | 
            ||
| 264 | |||
| 265 |                                                                                                     if ($(this).val() == "" || $(this).attr("type") == "password") { | 
            ||
| 266 |                                                                                                                         $(this).parent().removeClass("valid"); | 
            ||
| 267 |                                                                                                                         $(this).parent().removeClass("invalid"); | 
            ||
| 268 |                                                                                                     } else { | 
            ||
| 269 |                                                                                                                         $(this).parent().addClass("valid"); | 
            ||
| 270 |                                                                                                                         $(this).parent().removeClass("invalid"); | 
            ||
| 271 | }  | 
            ||
| 272 |                                                                                 } else { | 
            ||
| 273 | |||
| 274 |                                                                                                     if ($(this).attr("type") == "password") { | 
            ||
| 275 | return false;  | 
            ||
| 276 |                                                                                                     } else { | 
            ||
| 277 |                                                                                                                         $(this).parent().addClass("invalid"); | 
            ||
| 278 |                                                                                                                         $(this).parent().removeClass("valid"); | 
            ||
| 279 | }  | 
            ||
| 280 | }  | 
            ||
| 281 | });  | 
            ||
| 282 | }  | 
            ||
| 283 | |||
| 284 | labelHandlers();  | 
            ||
| 285 | |||
| 286 | //Individualize template attributes  | 
            ||
| 287 |                                         function appendToAttributes(parent, attribute, suffix, conditions) { | 
            ||
| 288 | var selector = "*[" + attribute + "]";  | 
            ||
| 289 | |||
| 290 | //If conditions is set, only modify attributes that also  | 
            ||
| 291 | //satisfy that selector  | 
            ||
| 292 |                                                             if (conditions) { | 
            ||
| 293 | selector = conditions + selector;  | 
            ||
| 294 | }  | 
            ||
| 295 | |||
| 296 |                                                             parent.find(selector).each(function () { | 
            ||
| 297 | $(this).attr(attribute, $(this).attr(attribute) + suffix);  | 
            ||
| 298 | });  | 
            ||
| 299 | }  | 
            ||
| 300 | |||
| 301 | //Return the next unused data-item-id value  | 
            ||
| 302 |                                         function getNextItemId(parent) { | 
            ||
| 303 | var maxId = 0;  | 
            ||
| 304 |                                                             parent.find("*[data-item-id]").each(function () { | 
            ||
| 305 |                                                                                 var id = parseInt($(this).attr('data-item-id')); | 
            ||
| 306 |                                                                                 if (id > maxId) { | 
            ||
| 307 | maxId = id;  | 
            ||
| 308 | }  | 
            ||
| 309 | });  | 
            ||
| 310 | return maxId + 1;  | 
            ||
| 311 | }  | 
            ||
| 312 | |||
| 313 | // Profile List Handlers ===============================================  | 
            ||
| 314 | |||
| 315 | // Add Profile Element  | 
            ||
| 316 |                                         function addProfileElement(trigger) { | 
            ||
| 317 | |||
| 318 | // Get Parent  | 
            ||
| 319 |                                                             var parent = $(trigger).parents(".profile-list"); | 
            ||
| 320 | |||
| 321 | // Get List Wrapper  | 
            ||
| 322 |                                                             var wrapper = parent.find(".profile-element-list"); | 
            ||
| 323 | |||
| 324 | // Set Null to Hidden  | 
            ||
| 325 |                                                             parent.find(".profile-null").removeClass("active"); | 
            ||
| 326 | |||
| 327 | // Get Template  | 
            ||
| 328 |                                                             var template = parent.find(".profile-element.template").clone(); | 
            ||
| 329 | |||
| 330 | // Remove Template Class  | 
            ||
| 331 |                                                             template.removeClass("template"); | 
            ||
| 332 | |||
| 333 | // Get New ID  | 
            ||
| 334 | var newId = getNextItemId(wrapper);  | 
            ||
| 335 | |||
| 336 |                                                             template.attr('data-item-id', newId); | 
            ||
| 337 | |||
| 338 | // Individualize Form IDs and labels  | 
            ||
| 339 | appendToAttributes(template, 'id', '_' + newId);  | 
            ||
| 340 | appendToAttributes(template, 'for', '_' + newId);  | 
            ||
| 341 | |||
| 342 | // Individualize form names, except for submit buttons  | 
            ||
| 343 | appendToAttributes(template, 'name', '[' + newId + ']', ':not([name=submit])');  | 
            ||
| 344 | // Individualize values on submit buttons  | 
            ||
| 345 | appendToAttributes(template, 'value', '[' + newId + ']', '[name=submit]');  | 
            ||
| 346 | |||
| 347 | // Prepend Clone to the Wrapper  | 
            ||
| 348 | wrapper.prepend(template);  | 
            ||
| 349 | |||
| 350 | // Reactivate Required Fields  | 
            ||
| 351 | requiredFields();  | 
            ||
| 352 | |||
| 353 | // Reactivate Labels  | 
            ||
| 354 | labelHandlers();  | 
            ||
| 355 | |||
| 356 | // Reactivate Nested Relatives  | 
            ||
| 357 | loadProfileRelatives();  | 
            ||
| 358 | }  | 
            ||
| 359 | |||
| 360 | // Click Trigger  | 
            ||
| 361 |                                         $(".profile-list__add-element-trigger").on("click", function (e) { | 
            ||
| 362 | |||
| 363 | // Prevent Default Functions  | 
            ||
| 364 | e.preventDefault();  | 
            ||
| 365 | |||
| 366 | // Add Profile Elements  | 
            ||
| 367 | addProfileElement(this);  | 
            ||
| 368 | });  | 
            ||
| 369 | |||
| 370 | // Enter Key Trigger  | 
            ||
| 371 |                                         $(".profile-list__add-element-trigger").on("keyup", function (e) { | 
            ||
| 372 | |||
| 373 |                                                             if (e.which == 13) { | 
            ||
| 374 | |||
| 375 | // Prevent Default Functions  | 
            ||
| 376 | e.preventDefault();  | 
            ||
| 377 | |||
| 378 | // Add Profile Elements  | 
            ||
| 379 | addProfileElement(this);  | 
            ||
| 380 | }  | 
            ||
| 381 | });  | 
            ||
| 382 | |||
| 383 | // Remove Profile Element  | 
            ||
| 384 | |||
| 385 | // Add Profile Relative  | 
            ||
| 386 |                                         function addProfileRelative(trigger) { | 
            ||
| 387 | |||
| 388 | // Get Parent  | 
            ||
| 389 |                                                             var parent = $(trigger).parents(".profile-relative-list"); | 
            ||
| 390 | |||
| 391 | // Get List Wrapper  | 
            ||
| 392 |                                                             var wrapper = parent.find(".profile-relative-list__wrapper"); | 
            ||
| 393 | |||
| 394 | // Set Null to Hidden  | 
            ||
| 395 |                                                             // parent.find(".profile-null").removeClass("active"); | 
            ||
| 396 | |||
| 397 | // Get Template  | 
            ||
| 398 |                                                             var template = parent.find(".profile-relative.template").clone(); | 
            ||
| 399 | |||
| 400 | // Remove Template Class  | 
            ||
| 401 |                                                             template.removeClass("template"); | 
            ||
| 402 | |||
| 403 | // Edit Form IDs  | 
            ||
| 404 | |||
| 405 | // Tristan, help! x_x  | 
            ||
| 406 | |||
| 407 | // Append Clone to the Wrapper  | 
            ||
| 408 | wrapper.append(template);  | 
            ||
| 409 | |||
| 410 | // Reactivate Required Fields  | 
            ||
| 411 | requiredFields();  | 
            ||
| 412 | |||
| 413 | // Reactivate Labels  | 
            ||
| 414 | labelHandlers();  | 
            ||
| 415 | |||
| 416 | // Reactivate Nested Relatives  | 
            ||
| 417 | loadProfileRelativeDeletion();  | 
            ||
| 418 | }  | 
            ||
| 419 | |||
| 420 | // Load Function  | 
            ||
| 421 |                                         function loadProfileRelatives() { | 
            ||
| 422 | |||
| 423 | // Click Trigger  | 
            ||
| 424 |                                                             $(".profile-relative__add-trigger").off("click"); | 
            ||
| 425 | |||
| 426 |                                                             $(".profile-relative__add-trigger").on("click", function (e) { | 
            ||
| 427 | |||
| 428 | // Prevent Default Functions  | 
            ||
| 429 | e.preventDefault();  | 
            ||
| 430 | |||
| 431 | // Add Profile Relative  | 
            ||
| 432 | addProfileRelative(this);  | 
            ||
| 433 | });  | 
            ||
| 434 | |||
| 435 | // Enter Key Trigger  | 
            ||
| 436 |                                                             $(".profile-relative__add-trigger").off("keyup"); | 
            ||
| 437 | |||
| 438 |                                                             $(".profile-relative__add-trigger").on("keyup", function (e) { | 
            ||
| 439 | |||
| 440 |                                                                                 if (e.which == 13) { | 
            ||
| 441 | |||
| 442 | // Prevent Default Functions  | 
            ||
| 443 | e.preventDefault();  | 
            ||
| 444 | |||
| 445 | // Add Profile Relative  | 
            ||
| 446 | addProfileRelative(this);  | 
            ||
| 447 | }  | 
            ||
| 448 | });  | 
            ||
| 449 | }  | 
            ||
| 450 | |||
| 451 | loadProfileRelatives();  | 
            ||
| 452 | |||
| 453 | // Remove Profile Relative  | 
            ||
| 454 |                                         function deleteProfileRelative(trigger) { | 
            ||
| 455 | |||
| 456 |                                                             $(trigger).parents(".profile-relative").remove(); | 
            ||
| 457 | }  | 
            ||
| 458 | |||
| 459 | // Load Function  | 
            ||
| 460 |                                         function loadProfileRelativeDeletion() { | 
            ||
| 461 | |||
| 462 | // Click Trigger  | 
            ||
| 463 |                                                             $(".profile-relative__remove-trigger").on("click", function (e) { | 
            ||
| 464 | |||
| 465 | // Prevent Default Functions  | 
            ||
| 466 | e.preventDefault();  | 
            ||
| 467 | |||
| 468 | // Delete Profile Relative  | 
            ||
| 469 | deleteProfileRelative(this);  | 
            ||
| 470 | });  | 
            ||
| 471 | |||
| 472 | // Enter Key Trigger  | 
            ||
| 473 |                                                             $(".profile-relative__remove-trigger").on("keyup", function (e) { | 
            ||
| 474 | |||
| 475 |                                                                                 if (e.which == 13) { | 
            ||
| 476 | |||
| 477 | // Prevent Default Functions  | 
            ||
| 478 | e.preventDefault();  | 
            ||
| 479 | |||
| 480 | // Delete Profile Relative  | 
            ||
| 481 | deleteProfileRelative(this);  | 
            ||
| 482 | }  | 
            ||
| 483 | });  | 
            ||
| 484 | }  | 
            ||
| 485 | |||
| 486 | loadProfileRelativeDeletion();  | 
            ||
| 487 | |||
| 488 | // Experience Handlers =================================================  | 
            ||
| 489 | |||
| 490 | // Degrees  | 
            ||
| 491 | |||
| 492 |                                         function addDegree(trigger) { | 
            ||
| 493 | |||
| 494 | // Get Wrapper  | 
            ||
| 495 |                                                             var wrapper = $(".application-post__experience-wrapper"); | 
            ||
| 496 | |||
| 497 | // Get Template  | 
            ||
| 498 |                                                             var template = $(".application-post__accordion--degree.template").clone(); | 
            ||
| 499 | |||
| 500 | // Get New ID  | 
            ||
| 501 |                                                             var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; | 
            ||
| 502 | |||
| 503 | // Remove Template Class  | 
            ||
| 504 |                                                             template.removeClass("template"); | 
            ||
| 505 | |||
| 506 | // Assign the New ID  | 
            ||
| 507 |                                                             template.attr("data-experience-id", newID); | 
            ||
| 508 | |||
| 509 | // Edit Form IDs  | 
            ||
| 510 | |||
| 511 | // Degree Type  | 
            ||
| 512 |                                                             template.find("[data-form-id*='experience-degree']").find("label").attr("for", "degree" + newID); | 
            ||
| 513 |                                                             template.find("[data-form-id*='experience-degree']").find("select").attr("id", "degree" + newID); | 
            ||
| 514 | |||
| 515 | // Area of Study  | 
            ||
| 516 |                                                             template.find("[data-form-id*='experience-aos']").find("label").attr("for", "areaOfStudy" + newID); | 
            ||
| 517 |                                                             template.find("[data-form-id*='experience-aos']").find("input").attr("id", "areaOfStudy" + newID); | 
            ||
| 518 | |||
| 519 | // Institution  | 
            ||
| 520 |                                                             template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); | 
            ||
| 521 |                                                             template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); | 
            ||
| 522 | |||
| 523 | // Start Date  | 
            ||
| 524 |                                                             template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); | 
            ||
| 525 |                                                             template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); | 
            ||
| 526 | |||
| 527 | // End Date  | 
            ||
| 528 |                                                             template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); | 
            ||
| 529 |                                                             template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); | 
            ||
| 530 | |||
| 531 | // Append Clone to the Wrapper  | 
            ||
| 532 | wrapper.append(template);  | 
            ||
| 533 | |||
| 534 | requiredFields();  | 
            ||
| 535 | labelHandlers();  | 
            ||
| 536 | }  | 
            ||
| 537 | |||
| 538 |                                         $("#addDegreeButton").on("click", function (e) { | 
            ||
| 539 | |||
| 540 | e.preventDefault();  | 
            ||
| 541 | |||
| 542 | addDegree(this);  | 
            ||
| 543 | });  | 
            ||
| 544 | |||
| 545 |                                         $("#addDegreeButton").on("keyup", function (e) { | 
            ||
| 546 | |||
| 547 |                                                             if (e.which == 13) { | 
            ||
| 548 | e.preventDefault();  | 
            ||
| 549 | addDegree(this);  | 
            ||
| 550 | }  | 
            ||
| 551 | });  | 
            ||
| 552 | |||
| 553 | // Courses  | 
            ||
| 554 | |||
| 555 |                                         function addCourse(trigger) { | 
            ||
| 556 | |||
| 557 | // Get Wrapper  | 
            ||
| 558 |                                                             var wrapper = $(".application-post__experience-wrapper"); | 
            ||
| 559 | |||
| 560 | // Get Template  | 
            ||
| 561 |                                                             var template = $(".application-post__accordion--course.template").clone(); | 
            ||
| 562 | |||
| 563 | // Get New ID  | 
            ||
| 564 |                                                             var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; | 
            ||
| 565 | |||
| 566 | // Remove Template Class  | 
            ||
| 567 |                                                             template.removeClass("template"); | 
            ||
| 568 | |||
| 569 | // Assign the New ID  | 
            ||
| 570 |                                                             template.attr("data-experience-id", newID); | 
            ||
| 571 | |||
| 572 | // Edit Form IDs  | 
            ||
| 573 | |||
| 574 | // Course Name  | 
            ||
| 575 |                                                             template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "courseName" + newID); | 
            ||
| 576 |                                                             template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "courseName" + newID); | 
            ||
| 577 | |||
| 578 | // Institution  | 
            ||
| 579 |                                                             template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); | 
            ||
| 580 |                                                             template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); | 
            ||
| 581 | |||
| 582 | // Start Date  | 
            ||
| 583 |                                                             template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); | 
            ||
| 584 |                                                             template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); | 
            ||
| 585 | |||
| 586 | // End Date  | 
            ||
| 587 |                                                             template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); | 
            ||
| 588 |                                                             template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); | 
            ||
| 589 | |||
| 590 | // Append Clone to the Wrapper  | 
            ||
| 591 | wrapper.append(template);  | 
            ||
| 592 | |||
| 593 | requiredFields();  | 
            ||
| 594 | labelHandlers();  | 
            ||
| 595 | }  | 
            ||
| 596 | |||
| 597 |                                         $("#addCourseButton").on("click", function (e) { | 
            ||
| 598 | |||
| 599 | e.preventDefault();  | 
            ||
| 600 | |||
| 601 | addCourse(this);  | 
            ||
| 602 | });  | 
            ||
| 603 | |||
| 604 |                                         $("#addCourseButton").on("keyup", function (e) { | 
            ||
| 605 | |||
| 606 |                                                             if (e.which == 13) { | 
            ||
| 607 | e.preventDefault();  | 
            ||
| 608 | addCourse(this);  | 
            ||
| 609 | }  | 
            ||
| 610 | });  | 
            ||
| 611 | |||
| 612 | // Work  | 
            ||
| 613 | |||
| 614 |                                         function addWork(trigger) { | 
            ||
| 615 | |||
| 616 | // Get Wrapper  | 
            ||
| 617 |                                                             var wrapper = $(".application-post__experience-wrapper"); | 
            ||
| 618 | |||
| 619 | // Get Template  | 
            ||
| 620 |                                                             var template = $(".application-post__accordion--work.template").clone(); | 
            ||
| 621 | |||
| 622 | // Get New ID  | 
            ||
| 623 |                                                             var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; | 
            ||
| 624 | |||
| 625 | // Remove Template Class  | 
            ||
| 626 |                                                             template.removeClass("template"); | 
            ||
| 627 | |||
| 628 | // Assign the New ID  | 
            ||
| 629 |                                                             template.attr("data-experience-id", newID); | 
            ||
| 630 | |||
| 631 | // Edit Form IDs  | 
            ||
| 632 | |||
| 633 | // Role  | 
            ||
| 634 |                                                             template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "role" + newID); | 
            ||
| 635 |                                                             template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "role" + newID); | 
            ||
| 636 | |||
| 637 | // Group / Company  | 
            ||
| 638 |                                                             template.find("[data-form-id*='experience-institution']").find("label").attr("for", "group" + newID); | 
            ||
| 639 |                                                             template.find("[data-form-id*='experience-institution']").find("input").attr("id", "group" + newID); | 
            ||
| 640 | |||
| 641 | // Description  | 
            ||
| 642 |                                                             template.find("[data-form-id*='experience-description']").find("label").attr("for", "description" + newID); | 
            ||
| 643 |                                                             template.find("[data-form-id*='experience-description']").find("input").attr("id", "description" + newID); | 
            ||
| 644 | |||
| 645 | // Start Date  | 
            ||
| 646 |                                                             template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); | 
            ||
| 647 |                                                             template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); | 
            ||
| 648 | |||
| 649 | // End Date  | 
            ||
| 650 |                                                             template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); | 
            ||
| 651 |                                                             template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); | 
            ||
| 652 | |||
| 653 | // Append Clone to the Wrapper  | 
            ||
| 654 | wrapper.append(template);  | 
            ||
| 655 | |||
| 656 | requiredFields();  | 
            ||
| 657 | labelHandlers();  | 
            ||
| 658 | }  | 
            ||
| 659 | |||
| 660 |                                         $("#addWorkButton").on("click", function (e) { | 
            ||
| 661 | |||
| 662 | e.preventDefault();  | 
            ||
| 663 | |||
| 664 | addWork(this);  | 
            ||
| 665 | });  | 
            ||
| 666 | |||
| 667 |                                         $("#addWorkButton").on("keyup", function (e) { | 
            ||
| 668 | |||
| 669 |                                                             if (e.which == 13) { | 
            ||
| 670 | e.preventDefault();  | 
            ||
| 671 | addWork(this);  | 
            ||
| 672 | }  | 
            ||
| 673 | });  | 
            ||
| 674 | |||
| 675 | // Create Job Handlers =================================================  | 
            ||
| 676 | |||
| 677 | // Tasks  | 
            ||
| 678 | |||
| 679 |                                         function addTask(trigger) { | 
            ||
| 680 | |||
| 681 | // Get Wrapper  | 
            ||
| 682 |                                                             var wrapper = $(".manager-jobs__create-task-wrapper"); | 
            ||
| 683 | |||
| 684 | // Get Template  | 
            ||
| 685 |                                                             var template = $(".manager-jobs__create-task.template").clone(); | 
            ||
| 686 | |||
| 687 |                                                             console.log(wrapper.find(".manager-jobs__create-task")); | 
            ||
| 688 | |||
| 689 | // Get New ID  | 
            ||
| 690 |                                                             if (wrapper.find(".manager-jobs__create-task").length == 0) { | 
            ||
| 691 |                                                                                 var newID = parseInt(template.attr("data-task-id")) + 1; | 
            ||
| 692 |                                                             } else { | 
            ||
| 693 |                                                                                 var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; | 
            ||
| 694 | }  | 
            ||
| 695 | |||
| 696 | // Remove Template Class  | 
            ||
| 697 |                                                             template.removeClass("template"); | 
            ||
| 698 | |||
| 699 | // Assign the New ID  | 
            ||
| 700 |                                                             template.attr("data-task-id", newID); | 
            ||
| 701 | |||
| 702 | // Add newID as suffix to all "id" and "for" attributes  | 
            ||
| 703 |                                                             template.find("*[id]").each(function () { | 
            ||
| 704 |                                                                                 $(this).attr("id", this.id + newID); | 
            ||
| 705 | });  | 
            ||
| 706 |                                                             template.find("*[for]").each(function () { | 
            ||
| 707 |                                                                                 $(this).attr("for", $(this).attr("for") + newID); | 
            ||
| 708 | });  | 
            ||
| 709 | |||
| 710 | // Replace :id with newID in all form names  | 
            ||
| 711 |                                                             template.find("*[name]").each(function () { | 
            ||
| 712 |                                                                                 $(this).attr('name', $(this).attr("name").replace(":id", newID)); | 
            ||
| 713 | });  | 
            ||
| 714 | |||
| 715 | // Task (English)  | 
            ||
| 716 |                                                             //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); | 
            ||
| 717 |                                                             //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); | 
            ||
| 718 | |||
| 719 | // Task (French)  | 
            ||
| 720 |                                                             //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); | 
            ||
| 721 |                                                             //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); | 
            ||
| 722 | |||
| 723 | // Append Clone to the Wrapper  | 
            ||
| 724 | wrapper.append(template);  | 
            ||
| 725 | |||
| 726 | requiredFields();  | 
            ||
| 727 | labelHandlers();  | 
            ||
| 728 | deleteTaskTrigger();  | 
            ||
| 729 | }  | 
            ||
| 730 | |||
| 731 |                                         $("#addTaskButton").on("click", function (e) { | 
            ||
| 732 | |||
| 733 | e.preventDefault();  | 
            ||
| 734 | |||
| 735 | addTask(this);  | 
            ||
| 736 | });  | 
            ||
| 737 | |||
| 738 |                                         $("#addTaskButton").on("keyup", function (e) { | 
            ||
| 739 | |||
| 740 |                                                             if (e.which == 13) { | 
            ||
| 741 | e.preventDefault();  | 
            ||
| 742 | addTask(this);  | 
            ||
| 743 | }  | 
            ||
| 744 | });  | 
            ||
| 745 | |||
| 746 | // Task Deletion  | 
            ||
| 747 | |||
| 748 |                                         function deleteTask(trigger) { | 
            ||
| 749 | |||
| 750 |                                                             $(trigger).parents(".manager-jobs__create-task").remove(); | 
            ||
| 751 | }  | 
            ||
| 752 | |||
| 753 |                                         function deleteTaskTrigger() { | 
            ||
| 754 | |||
| 755 |                                                             $(".manager-jobs__delete-task-button").on("click", function (e) { | 
            ||
| 756 | |||
| 757 | e.preventDefault();  | 
            ||
| 758 | |||
| 759 | deleteTask(this);  | 
            ||
| 760 | });  | 
            ||
| 761 | |||
| 762 |                                                             $(".manager-jobs__delete-task-button").on("keyup", function (e) { | 
            ||
| 763 | |||
| 764 |                                                                                 if (e.which == 13) { | 
            ||
| 765 | e.preventDefault();  | 
            ||
| 766 | deleteTask(this);  | 
            ||
| 767 | }  | 
            ||
| 768 | });  | 
            ||
| 769 | }  | 
            ||
| 770 | |||
| 771 | deleteTaskTrigger();  | 
            ||
| 772 | |||
| 773 | // Skills  | 
            ||
| 774 | |||
| 775 |                                         function addSkill(trigger) { | 
            ||
| 776 | |||
| 777 | // Get Parent  | 
            ||
| 778 |                                                             var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); | 
            ||
| 779 | |||
| 780 | // Get Wrapper  | 
            ||
| 781 |                                                             var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); | 
            ||
| 782 | |||
| 783 | // Get Template  | 
            ||
| 784 |                                                             var template = parent.find(".manager-jobs__create-skill.template").clone(); | 
            ||
| 785 | |||
| 786 |                                                             console.log(wrapper.find(".manager-jobs__create-skill")); | 
            ||
| 787 | |||
| 788 | // Get New ID  | 
            ||
| 789 |                                                             if (wrapper.find(".manager-jobs__create-skill").length == 0) { | 
            ||
| 790 |                                                                                 var newID = parseInt(template.attr("data-skill-id")) + 1; | 
            ||
| 791 |                                                             } else { | 
            ||
| 792 |                                                                                 var newID = parseInt(wrapper.find("[class*='manager-jobs__create-skill']").last().attr("data-skill-id")) + 1; | 
            ||
| 793 | }  | 
            ||
| 794 | |||
| 795 | // Remove Template Class  | 
            ||
| 796 |                                                             template.removeClass("template"); | 
            ||
| 797 | |||
| 798 | // Assign the New ID  | 
            ||
| 799 |                                                             template.attr("data-skill-id", newID); | 
            ||
| 800 | |||
| 801 | // Add newID as suffix to all "id" and "for" attributes  | 
            ||
| 802 |                                                             template.find("*[id]").each(function () { | 
            ||
| 803 |                                                                                 $(this).attr("id", this.id + newID); | 
            ||
| 804 | });  | 
            ||
| 805 |                                                             template.find("*[for]").each(function () { | 
            ||
| 806 |                                                                                 $(this).attr("for", $(this).attr("for") + newID); | 
            ||
| 807 | });  | 
            ||
| 808 | |||
| 809 | // Replace :id with newID in all form names  | 
            ||
| 810 |                                                             template.find("*[name]").each(function () { | 
            ||
| 811 |                                                                                 $(this).attr('name', $(this).attr("name").replace(":id", newID)); | 
            ||
| 812 | });  | 
            ||
| 813 | |||
| 814 | // Edit Form IDs  | 
            ||
| 815 | //  | 
            ||
| 816 | // // Queestion (English)  | 
            ||
| 817 |                                                             // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); | 
            ||
| 818 |                                                             // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); | 
            ||
| 819 | //  | 
            ||
| 820 | // // Queestion (French)  | 
            ||
| 821 |                                                             // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); | 
            ||
| 822 |                                                             // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); | 
            ||
| 823 | |||
| 824 | // Append Clone to the Wrapper  | 
            ||
| 825 | wrapper.append(template);  | 
            ||
| 826 | |||
| 827 | requiredFields();  | 
            ||
| 828 | labelHandlers();  | 
            ||
| 829 | deleteSkillTrigger();  | 
            ||
| 830 | }  | 
            ||
| 831 | |||
| 832 |                                         $(".manager-jobs__add-skill-button").on("click", function (e) { | 
            ||
| 833 | |||
| 834 | e.preventDefault();  | 
            ||
| 835 | |||
| 836 | addSkill(this);  | 
            ||
| 837 | });  | 
            ||
| 838 | |||
| 839 |                                         $(".manager-jobs__add-skill-button").on("keyup", function (e) { | 
            ||
| 840 | |||
| 841 |                                                             if (e.which == 13) { | 
            ||
| 842 | e.preventDefault();  | 
            ||
| 843 | addSkill(this);  | 
            ||
| 844 | }  | 
            ||
| 845 | });  | 
            ||
| 846 | |||
| 847 | // Skill Deletion  | 
            ||
| 848 | |||
| 849 |                                         function deleteSkill(trigger) { | 
            ||
| 850 | |||
| 851 |                                                             $(trigger).parents(".manager-jobs__create-skill").remove(); | 
            ||
| 852 | }  | 
            ||
| 853 | |||
| 854 |                                         function deleteSkillTrigger() { | 
            ||
| 855 | |||
| 856 |                                                             $(".manager-jobs__delete-skill-button").on("click", function (e) { | 
            ||
| 857 | |||
| 858 | e.preventDefault();  | 
            ||
| 859 | |||
| 860 | deleteSkill(this);  | 
            ||
| 861 | });  | 
            ||
| 862 | |||
| 863 |                                                             $(".manager-jobs__delete-skill-button").on("keyup", function (e) { | 
            ||
| 864 | |||
| 865 |                                                                                 if (e.which == 13) { | 
            ||
| 866 | e.preventDefault();  | 
            ||
| 867 | deleteSkill(this);  | 
            ||
| 868 | }  | 
            ||
| 869 | });  | 
            ||
| 870 | }  | 
            ||
| 871 | |||
| 872 | deleteSkillTrigger();  | 
            ||
| 873 | |||
| 874 | // Questions  | 
            ||
| 875 | |||
| 876 |                                         function addQuestion(trigger) { | 
            ||
| 877 | |||
| 878 | // Get Wrapper  | 
            ||
| 879 |                                                             var wrapper = $(".manager-jobs__create-question-wrapper"); | 
            ||
| 880 | |||
| 881 | // Get Template  | 
            ||
| 882 |                                                             var template = $(".manager-jobs__create-question.template").clone(); | 
            ||
| 883 | |||
| 884 |                                                             console.log(wrapper.find(".manager-jobs__create-question")); | 
            ||
| 885 | |||
| 886 | // Get New ID  | 
            ||
| 887 |                                                             if (wrapper.find(".manager-jobs__create-question").length == 0) { | 
            ||
| 888 |                                                                                 var newID = parseInt(template.attr("data-question-id")) + 1; | 
            ||
| 889 |                                                             } else { | 
            ||
| 890 |                                                                                 var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; | 
            ||
| 891 | }  | 
            ||
| 892 | |||
| 893 | // Remove Template Class  | 
            ||
| 894 |                                                             template.removeClass("template"); | 
            ||
| 895 | |||
| 896 | // Assign the New ID  | 
            ||
| 897 |                                                             template.attr("data-question-id", newID); | 
            ||
| 898 | |||
| 899 | // Add newID as suffix to all "id" and "for" attributes  | 
            ||
| 900 |                                                             template.find("*[id]").each(function () { | 
            ||
| 901 |                                                                                 $(this).attr("id", this.id + newID); | 
            ||
| 902 | });  | 
            ||
| 903 |                                                             template.find("*[for]").each(function () { | 
            ||
| 904 |                                                                                 $(this).attr("for", $(this).attr("for") + newID); | 
            ||
| 905 | });  | 
            ||
| 906 | |||
| 907 | // Replace :id with newID in all form names  | 
            ||
| 908 |                                                             template.find("*[name]").each(function () { | 
            ||
| 909 |                                                                                 $(this).attr('name', $(this).attr("name").replace(":id", newID)); | 
            ||
| 910 | });  | 
            ||
| 911 | |||
| 912 | // Edit Form IDs  | 
            ||
| 913 | //  | 
            ||
| 914 | // // Queestion (English)  | 
            ||
| 915 |                                                             // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); | 
            ||
| 916 |                                                             // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); | 
            ||
| 917 | //  | 
            ||
| 918 | // // Queestion (French)  | 
            ||
| 919 |                                                             // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); | 
            ||
| 920 |                                                             // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); | 
            ||
| 921 | |||
| 922 | // Append Clone to the Wrapper  | 
            ||
| 923 | wrapper.append(template);  | 
            ||
| 924 | |||
| 925 | requiredFields();  | 
            ||
| 926 | labelHandlers();  | 
            ||
| 927 | deleteQuestionTrigger();  | 
            ||
| 928 | }  | 
            ||
| 929 | |||
| 930 |                                         $("#addQuestionButton").on("click", function (e) { | 
            ||
| 931 | |||
| 932 | e.preventDefault();  | 
            ||
| 933 | |||
| 934 | addQuestion(this);  | 
            ||
| 935 | });  | 
            ||
| 936 | |||
| 937 |                                         $("#addQuestionButton").on("keyup", function (e) { | 
            ||
| 938 | |||
| 939 |                                                             if (e.which == 13) { | 
            ||
| 940 | e.preventDefault();  | 
            ||
| 941 | addQuestion(this);  | 
            ||
| 942 | }  | 
            ||
| 943 | });  | 
            ||
| 944 | |||
| 945 | // Question Deletion  | 
            ||
| 946 | |||
| 947 |                                         function deleteQuestion(trigger) { | 
            ||
| 948 | |||
| 949 |                                                             $(trigger).parents(".manager-jobs__create-question").remove(); | 
            ||
| 950 | }  | 
            ||
| 951 | |||
| 952 |                                         function deleteQuestionTrigger() { | 
            ||
| 953 | |||
| 954 |                                                             $(".manager-jobs__delete-question-button").on("click", function (e) { | 
            ||
| 955 | |||
| 956 | e.preventDefault();  | 
            ||
| 957 | |||
| 958 | deleteQuestion(this);  | 
            ||
| 959 | });  | 
            ||
| 960 | |||
| 961 |                                                             $(".manager-jobs__delete-question-button").on("keyup", function (e) { | 
            ||
| 962 | |||
| 963 |                                                                                 if (e.which == 13) { | 
            ||
| 964 | e.preventDefault();  | 
            ||
| 965 | deleteQuestion(this);  | 
            ||
| 966 | }  | 
            ||
| 967 | });  | 
            ||
| 968 | }  | 
            ||
| 969 | |||
| 970 | deleteQuestionTrigger();  | 
            ||
| 971 | });  | 
            ||
| 972 | })(jQuery);  | 
            ||
| 973 | |||
| 991 | /******/ ]);  |